// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-03-28 16:32
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.DateTrain;

public class HasAlternatingBits {
    /**
     * 使用判断给定数值的二进制数是否是01间隔的
     *
     * @param n
     * @return
     */
    public boolean hasAlternatingBits(int n) {
        for (int i = 1; i < 32; i++) {
            if ((n >> i) == 0) {
                break;
            }
            int j = i - 1;
            if ((((n >> i) & 1) & ((n >> j) & 1)) == 1) {
                return false;
            }
        }
        return true;
    }
}
